﻿using System.Collections.Generic;

namespace QuantBox.XApi
{
    internal class OrderMap
    {
        private readonly Dictionary<string, OrderField> _orders = new Dictionary<string, OrderField>();
        private readonly Dictionary<int, string> _localIdMap = new Dictionary<int, string>();

        public void AddOrder(OrderField order)
        {
            _orders[order.ID] = order;
            _localIdMap[int.Parse(order.LocalID)] = order.ID;
        }

        public OrderField? Get(string id)
        {
            if (_orders.TryGetValue(id, out var order)) {
                return order;
            }
            return null;
        }

        public OrderField? GetByLocalId(int localId)
        {
            if (_localIdMap.TryGetValue(localId, out var id) && _orders.TryGetValue(id, out var order)) {
                return order;
            }
            return null;
        }
    }
}